package tbs.littlebaby;

import AppSystem.Settinger;
import Data.BasicData;
import Data.SaveFeature;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.ConstraintLayout;

import java.util.Random;

import static AppSystem.PermissionRequest.verifyStoragePermissions;

public class MainActivity extends AppCompatActivity {
    public  static SaveFeature save;

    void ChangeBackGround()
    {
        int[] ids=new int[]{R.mipmap.main,R.mipmap.maina,R.mipmap.mainb,R.mipmap.mainc,R.mipmap.maind,R.mipmap.maine,R.mipmap.mainf,R.mipmap.maing};
        String[] exchangeWords=new String[]{"已为你更换壁纸了~","恭喜你发现了神奇功能~"," (〃・ｏ・〃) ","这张壁纸怎么样？？","(・ε・；)"," (・▽・。)","换个壁纸换个心情( ・ˍ・)"};
        int id=ids[random.nextInt(ids.length)];
        Bitmap bitmap=BitmapFactory.decodeResource(this.getResources(),id);
        BitmapDrawable bd=new BitmapDrawable(bitmap);
        Settinger.setImgId(id);
        findViewById(R.id.main).setBackground(bd);
        Toast.makeText(this,exchangeWords[random.nextInt(exchangeWords.length)],Toast.LENGTH_SHORT).show();
    }

    void TEST()
    {
        BasicData data=new BasicData("衣服",1,22.5,"就是好","就是棒",null,null,"你好世界");
        String t=data.toString();
      BasicData d=  BasicData.StringToData(t);
       d.toString();
    }

    void Init()
    {
        //TEST();
        ConstraintLayout m= findViewById(R.id.main);
        m.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ChangeBackGround();
                return false;
            }
        });
        findViewById(R.id.card_welcome).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Intent intent=new Intent(MainActivity.this,Setting.class);
                startActivity(intent);
                return false;
            }
        });
    }

    @Override
    protected void onResume() {
        if(Settinger.isLockImage())
        {
            Bitmap bitmap=BitmapFactory.decodeResource(this.getResources(),Settinger.getImgId());
            BitmapDrawable bd=new BitmapDrawable(bitmap);
            findViewById(R.id.main).setBackground(bd);
        }
        else
            ChangeBackGround();
        super.onResume();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        verifyStoragePermissions(this);
        Settinger.ReadSetting(this);
        save=new SaveFeature(this);

        Init();
        // save.Add(new BasicData(getString(R.string.Tag_cloth), BasicData.上衣,99,"就是好上衣","就是好",BasicData.strToDateLong("2002-09-23 00:00:00"),null,null));
    }
    Random random=new Random();
    void WelcomeClick()
    {
        CardView view=findViewById(R.id.card_welcome);
        String[] word=new String[]{"Love U","你最美了","超可爱是不是？","超喜欢你的呢~","小可爱乖乖的啊~"," (๑￫ܫ￩) ","小可爱来亲一口~Mua~~~","(｡・`ω´･)","(* ￣ー￣)"};
        int[] values=new int[]{Color.parseColor("#ef4136"),Color.parseColor("#f58f98"),Color.parseColor("#65c294"),Color.parseColor("#f58220"),Color.parseColor("#7bbfea"),Color.parseColor("#ffd400"),Color.parseColor("#f15a22"),Color.parseColor("#b22c46"),Color.parseColor("#f05b72")};
        ObjectAnimator animator=ObjectAnimator.ofInt(view,"CardBackgroundColor",values[random.nextInt(values.length)]);
        int d=random.nextInt(1400)+600;
        animator.setDuration(d);
        animator.setEvaluator(new ArgbEvaluator());
        Animation scale= AnimationUtils.loadAnimation(this,R.anim.scale);
        animator.start();
        view.startAnimation(scale);
        Toast.makeText(this,word[random.nextInt(word.length)],Toast.LENGTH_SHORT).show();
    }

    void GoDetail(int pos,String[] group)
    {
        Intent intent = new Intent(this, ItemList.class);
        intent=  intent.putExtra("pos",pos);
        intent=intent.putExtra("parts",group);
        startActivity(intent);
    }


  public   void CardClick(View V)
    {
        String tag=V.getTag().toString();
        if(tag.equals(getString(R.string.Tag_cloth)))
        {
            GoDetail(R.string.Tag_cloth,new String[]{"上衣","裤子","裙子","其他衣服"});
        }
        else if(tag.equals(getString(R.string.Tag_huazhuang)))
        {
            GoDetail(R.string.Tag_huazhuang,new String[]{"口红","散粉","腮红","粉底","眼影","眼线","护肤品","其他化妆品"});
        }
        else if (tag.equals(getString(R.string.Tag_pack)))
        {
            GoDetail(R.string.Tag_pack,new String[]{"双肩包","斜挎包","手提包","钱包","其他包包"});
        }
        else if (tag.equals(getString(R.string.Tag_shoe)))
        {
            GoDetail(R.string.Tag_shoe,new String[]{"凉鞋","皮鞋","运动鞋","高跟鞋","休闲鞋","靴子","其他鞋子"});
        }
        else if(tag.equals(getString(R.string.Tag_shoushi)))
        {
            GoDetail(R.string.Tag_shoushi,new String[]{"耳饰","颈饰","手饰","发饰","其它饰品"});
        }
        else if(tag.equals(getString(R.string.Tag_welcome)))
        {
            WelcomeClick();
        }
        else
        {
            Toast.makeText(this,"点击错误,功能未添加",Toast.LENGTH_SHORT).show();
        }
    }
}